/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package project;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author jon
 */
public class Newspaper {
    private String newspaper_name;
    private int address_zipcode;
    private String address_state;
    private String address_city;
    private String address_street;
    private double cost_of;
    private Date date_of;
    private int property_id;

    public Newspaper(String newspaper_name, int address_zipcode, String address_state, String address_city, String address_street,
            double cost_of, Date date_of, int property_id) {
        this.newspaper_name = newspaper_name;
        this.address_zipcode = address_zipcode;
        this.address_state = address_state;
        this.address_city = address_city;
        this.address_street = address_street;
        this.cost_of = cost_of;
        this.date_of = date_of;
        this.property_id = property_id;
    }


    /**
     * @return the newspaper_name
     */
    public String getNewspaper_name() {
        return newspaper_name;
    }

    /**
     * @param newspaper_name the newspaper_name to set
     */
    public void setNewspaper_name(String newspaper_name) {
        this.newspaper_name = newspaper_name;
    }

    /**
     * @return the address_zipcode
     */
    public int getAddress_zipcode() {
        return address_zipcode;
    }

    /**
     * @param address_zipcode the address_zipcode to set
     */
    public void setAddress_zipcode(int address_zipcode) {
        this.address_zipcode = address_zipcode;
    }

    /**
     * @return the address_state
     */
    public String getAddress_state() {
        return address_state;
    }

    /**
     * @param address_state the address_state to set
     */
    public void setAddress_state(String address_state) {
        this.address_state = address_state;
    }

    /**
     * @return the address_city
     */
    public String getAddress_city() {
        return address_city;
    }

    /**
     * @param address_city the address_city to set
     */
    public void setAddress_city(String address_city) {
        this.address_city = address_city;
    }

    /**
     * @return the address_street
     */
    public String getAddress_street() {
        return address_street;
    }

    /**
     * @param address_street the address_street to set
     */
    public void setAddress_street(String address_street) {
        this.address_street = address_street;
    }

    public void insert()
    {
        try
        {
            String host = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "jon";
            String password = "chaosecco";
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);

            Connection connection = DriverManager.getConnection(host,
                    username, password);
            System.out.print("Connected successfully.");
            String insertQuery = "INSERT INTO NEWSPAPER(" +
                    "newspaper_name, " +
                    "address_zipcode, "  +
                    "address_state, " +
                    "address_city, " +
                    "address_street, " +
                    "cost_of, " +
                    "date_of, " +
                    "property_number)" +
                    "VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement ps = connection.prepareStatement(insertQuery);
            ps.setString(1, newspaper_name);
            ps.setInt(2, address_zipcode);
            ps.setString(3, address_state);
            ps.setString(4, address_city);
            ps.setString(5, address_street);
            ps.setDouble(6, cost_of);
            ps.setDate(7, date_of);
            ps.setInt(8, property_id);
            ps.executeUpdate();

            connection.close();
        }

        catch (SQLException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }

        catch(ClassNotFoundException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }
    }

    /**
     * @return the cost_of
     */
    public double getCost_of() {
        return cost_of;
    }

    /**
     * @param cost_of the cost_of to set
     */
    public void setCost_of(double cost_of) {
        this.cost_of = cost_of;
    }

    /**
     * @return the date_of
     */
    public Date getDate_of() {
        return date_of;
    }

    /**
     * @param date_of the date_of to set
     */
    public void setDate_of(Date date_of) {
        this.date_of = date_of;
    }

    /**
     * @return the property_id
     */
    public int getProperty_id() {
        return property_id;
    }

    /**
     * @param property_id the property_id to set
     */
    public void setProperty_id(int property_id) {
        this.property_id = property_id;
    }
}
